package org.zzz.mapper;
import org.apache.ibatis.annotations.*;
import org.zzz.entity.User;


import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/19 15:12
 */
public interface UserMapper {
    @Select("select * from user")
    List<User> getUser();

    /**
     *
     * 根据用户名和密码查询
     * @param username
     * @param password
     * @return
     */
    @Select("select * from user where username = #{username} and password = #{password}")
    User getUserByUsernameAndPassword(@Param("username") String username,@Param("password") String password);

    /**
     * 添加用户信息
     * @param user
     * @return
     */
    @Insert("insert into user(username,password,role_id) value(#{username},#{password},#{roleId})")
    int insertUser(User user);

    /**
     * 通过username获取user
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getUserByUsername(@Param("username") String username);

    @Delete("delete from user where username = #{username}")
    int deleteUserByUsername(@Param("username") String username);

    /**
     * 更改用户id
     * @param sourceId
     * @param targetId
     * @return
     */
    @Update("update user set username = #{targetId} where username = #{sourceId}")
    int updateUserById(@Param("sourceId") String sourceId,@Param("targetId") String targetId);
}
